#include <iostream>

using std::cout;
using std::endl;

class Test
{
public:
    Test(int test)
    : _itest(test)
    {   cout << "Test(int)"<< endl;    }

    ~Test() {   cout << "~Test()" << endl;  }

    void print() const 
    {   cout <<"Test::_itest:" << _itest << endl;   }


private:
    int _itest;
};

class Base
{
public:
//protected:

    //当基类中定义了有参构造函数时，系统就不会再提供默认构造函数
    Base()
    //: _base(0)
    {   cout << "Base()" << endl;}

    Base(long base)
    : _base(base)
    {   
        cout << "Base(long)" << endl;
    }

    ~Base() {   cout << "~Base()" << endl;  }
    
    void print() const
    {   cout << "Base::_base:" << _base << endl;    }
private:
    long _base;
};

class Derived
: public Base
{
public:
    Derived(long base, int t, long derived)
    : _test(t)  //初始化对象成员时，以对象名调用相应的构造函数
    , Base(base)//基类构造函数能够调用是因为该构造函数是public的
    , _derived(derived)
    {   cout << "Derived(long,long)" << endl;}

    ~Derived() {    cout << "~Derived()" << endl;}

    void display() const
    {
        cout << "_derived:" << _derived << endl;
    }

private:
    Test _test;
    long _derived;
};

int main()
{
    Derived d1(1, 10, 100);
    d1.print();
    d1.display();

    return 0;
}

